package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysCourseEvaluate;
import com.hl.sfzy.service.SysCourseEvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;
import java.util.Map;

/**
 * @program: sfzy
 * @ClassName SysCourseEvaluateController
 * @description:
 * @author: lyp
 * @create: 2024-07-12 19:08
 * @Version 1.0
 **/
@RestController
public class SysCourseEvaluateController {
    @Autowired
    private SysCourseEvaluateService sysCourseEvaluateService;

    //新增
    @PostMapping("/sysCourseEvaluate")
    public Result add(@RequestBody SysCourseEvaluate sysCourseEvaluate){
        int num = sysCourseEvaluateService.add(sysCourseEvaluate);
        return num > 0 ? Result.success() : Result.error();
    }

    //删除
    @DeleteMapping("/sysCourseEvaluate/{id}")
    public Result remove(@PathVariable("id") Integer id){
        int num = sysCourseEvaluateService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/sysCourseEvaluate")
    public Result removeBatch(Integer[] ids){
        int num = sysCourseEvaluateService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    //修改
    @PutMapping("/sysCourseEvaluate")
    public Result edit(@RequestBody SysCourseEvaluate sysCourseEvaluate){
        int num = sysCourseEvaluateService.edit(sysCourseEvaluate);
        return num > 0 ? Result.success() : Result.error();
    }

    //根据id查询
    @GetMapping("/sysCourseEvaluate/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysCourseEvaluate sysCourseEvaluate = sysCourseEvaluateService.findById(id);
        return Result.success(sysCourseEvaluate);
    }

    //查询所有
    @GetMapping("/sysCourseEvaluate")
    public Result findAll(SysCourseEvaluate sysCourseEvaluate){
        List<SysCourseEvaluate> list = sysCourseEvaluateService.find(sysCourseEvaluate);
        return Result.success(list);
    }

    //分页查询
    @GetMapping("/sysCourseEvaluate/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM,required = false,defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE,required = false,defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysCourseEvaluate sysCourseEvaluate){
        Map<String,Object> map = sysCourseEvaluateService.findPage(pageNum, pageSize, sysCourseEvaluate);

        return Result.success(map);
    }
}

